package zzz.tuan2d.thuchi;

import java.util.ArrayList;

import zzz.tuan2d.toidihoilo.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * CategoryAdapter
 * 
 * @author TUAN2D
 */
public class ListCategoryAdapter extends BaseAdapter {
	private LayoutInflater mLayoutInflater;
	private ArrayList<CategoryModel> mListCategory;

	public ListCategoryAdapter(Context context,
			ArrayList<CategoryModel> mListCategory) {
		this.mListCategory = mListCategory;
		mLayoutInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return mListCategory.size();
	}

	@Override
	public Object getItem(int position) {
		return 0;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolderCategoryItem viewHolder;
		if (convertView == null) {
			// initial for the first time of this row
			convertView = mLayoutInflater.inflate(R.layout.item_category, null);
			viewHolder = new ViewHolderCategoryItem();
			viewHolder.textViewCategoryName = (TextView) convertView
					.findViewById(R.id.textViewCategoryName);
			viewHolder.textViewCategoryRecords = (TextView) convertView
					.findViewById(R.id.textViewCategoryRecords);
			convertView.setTag(viewHolder);
		} else {
			// initial for not the first time of this row
			viewHolder = (ViewHolderCategoryItem) convertView.getTag();
		}

		viewHolder.textViewCategoryName
				.setText(mListCategory.get(position).categoryName);
		viewHolder.textViewCategoryRecords.setText(""
				+ mListCategory.get(position).numberOfRecord);
		return convertView;
	}

	/**
	 * ViewHolderCategoryItem
	 * 
	 * @author TUAN2D : this class will contains all of the screen's fields
	 */
	private static class ViewHolderCategoryItem {
		private TextView textViewCategoryName, textViewCategoryRecords;
	}
}
